package common.util;

import common.ListNode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author : wenchao.long
 * @date : Created in 2023-12-19 下午 5:24 周二
 * @description :
 */
public class ListNodeUtil {

	public static ListNode create(Integer... nums) {
		if (nums == null) {
			return null;
		}
		List<Integer> result = new ArrayList<>(Arrays.asList(nums));
		return getNode(new ListNode(), 0, result);
	}

	private static ListNode getNode(ListNode node, int index, List<Integer> arr) {
		if (index == arr.size()) {
			return null;
		}
		node.val = arr.get(index);
		node.next = getNode(new ListNode(), index + 1, arr);
		return node;
	}

	public static void main(String[] args) {
		ListNode listNode = ListNodeUtil.create(1, 2, 3, 4, 5);
		System.out.println(listNode);
	}

}
